/**
 * 
 */
package br.srv.full.postalservices.faces.components;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.event.MethodExpressionValueChangeListener;
import javax.faces.validator.MethodExpressionValidator;
import javax.faces.webapp.UIComponentELTag;
import javax.servlet.jsp.JspException;

/**
 * @author Carlos Delfino
 * 
 */
public class LocaleUIComponentTag extends UIComponentELTag {

	// Setter Methods
	// PROPERTY: converter
	private javax.el.ValueExpression converter;

	public void setConverter(javax.el.ValueExpression converter) {
		this.converter = converter;
	}

	// PROPERTY: converterMessage
	private javax.el.ValueExpression converterMessage;

	public void setConverterMessage(javax.el.ValueExpression converterMessage) {
		this.converterMessage = converterMessage;
	}

	// PROPERTY: immediate
	private javax.el.ValueExpression immediate;

	public void setImmediate(javax.el.ValueExpression immediate) {
		this.immediate = immediate;
	}

	// PROPERTY: required
	private javax.el.ValueExpression required;

	public void setRequired(javax.el.ValueExpression required) {
		this.required = required;
	}

	// PROPERTY: requiredMessage
	private javax.el.ValueExpression requiredMessage;

	public void setRequiredMessage(javax.el.ValueExpression requiredMessage) {
		this.requiredMessage = requiredMessage;
	}

	// PROPERTY: validator
	private javax.el.MethodExpression validator;

	public void setValidator(javax.el.MethodExpression validator) {
		this.validator = validator;
	}

	// PROPERTY: validatorMessage
	private javax.el.ValueExpression validatorMessage;

	public void setValidatorMessage(javax.el.ValueExpression validatorMessage) {
		this.validatorMessage = validatorMessage;
	}

	// PROPERTY: value
	private javax.el.ValueExpression value;

	public void setValue(javax.el.ValueExpression value) {
		this.value = value;
	}

	// PROPERTY: valueChangeListener
	private javax.el.MethodExpression valueChangeListener;

	public void setValueChangeListener(javax.el.MethodExpression valueChangeListener) {
		this.valueChangeListener = valueChangeListener;
	}

	// PROPERTY: accesskey
	private javax.el.ValueExpression accesskey;

	public void setAccesskey(javax.el.ValueExpression accesskey) {
		this.accesskey = accesskey;
	}

	// PROPERTY: alt
	private javax.el.ValueExpression alt;

	public void setAlt(javax.el.ValueExpression alt) {
		this.alt = alt;
	}

	// PROPERTY: autocomplete
	private javax.el.ValueExpression autocomplete;

	public void setAutocomplete(javax.el.ValueExpression autocomplete) {
		this.autocomplete = autocomplete;
	}

	// PROPERTY: dir
	private javax.el.ValueExpression dir;

	public void setDir(javax.el.ValueExpression dir) {
		this.dir = dir;
	}

	// PROPERTY: disabled
	private javax.el.ValueExpression disabled;

	public void setDisabled(javax.el.ValueExpression disabled) {
		this.disabled = disabled;
	}

	// PROPERTY: label
	private javax.el.ValueExpression label;

	public void setLabel(javax.el.ValueExpression label) {
		this.label = label;
	}

	// PROPERTY: lang
	private javax.el.ValueExpression lang;

	public void setLang(javax.el.ValueExpression lang) {
		this.lang = lang;
	}

	// PROPERTY: maxlength
	private javax.el.ValueExpression maxlength;

	public void setMaxlength(javax.el.ValueExpression maxlength) {
		this.maxlength = maxlength;
	}

	// PROPERTY: onblur
	private javax.el.ValueExpression onblur;

	public void setOnblur(javax.el.ValueExpression onblur) {
		this.onblur = onblur;
	}

	// PROPERTY: onchange
	private javax.el.ValueExpression onchange;

	public void setOnchange(javax.el.ValueExpression onchange) {
		this.onchange = onchange;
	}

	// PROPERTY: onclick
	private javax.el.ValueExpression onclick;

	public void setOnclick(javax.el.ValueExpression onclick) {
		this.onclick = onclick;
	}

	// PROPERTY: ondblclick
	private javax.el.ValueExpression ondblclick;

	public void setOndblclick(javax.el.ValueExpression ondblclick) {
		this.ondblclick = ondblclick;
	}

	// PROPERTY: onfocus
	private javax.el.ValueExpression onfocus;

	public void setOnfocus(javax.el.ValueExpression onfocus) {
		this.onfocus = onfocus;
	}

	// PROPERTY: onkeydown
	private javax.el.ValueExpression onkeydown;

	public void setOnkeydown(javax.el.ValueExpression onkeydown) {
		this.onkeydown = onkeydown;
	}

	// PROPERTY: onkeypress
	private javax.el.ValueExpression onkeypress;

	public void setOnkeypress(javax.el.ValueExpression onkeypress) {
		this.onkeypress = onkeypress;
	}

	// PROPERTY: onkeyup
	private javax.el.ValueExpression onkeyup;

	public void setOnkeyup(javax.el.ValueExpression onkeyup) {
		this.onkeyup = onkeyup;
	}

	// PROPERTY: onmousedown
	private javax.el.ValueExpression onmousedown;

	public void setOnmousedown(javax.el.ValueExpression onmousedown) {
		this.onmousedown = onmousedown;
	}

	// PROPERTY: onmousemove
	private javax.el.ValueExpression onmousemove;

	public void setOnmousemove(javax.el.ValueExpression onmousemove) {
		this.onmousemove = onmousemove;
	}

	// PROPERTY: onmouseout
	private javax.el.ValueExpression onmouseout;

	public void setOnmouseout(javax.el.ValueExpression onmouseout) {
		this.onmouseout = onmouseout;
	}

	// PROPERTY: onmouseover
	private javax.el.ValueExpression onmouseover;

	public void setOnmouseover(javax.el.ValueExpression onmouseover) {
		this.onmouseover = onmouseover;
	}

	// PROPERTY: onmouseup
	private javax.el.ValueExpression onmouseup;

	public void setOnmouseup(javax.el.ValueExpression onmouseup) {
		this.onmouseup = onmouseup;
	}

	// PROPERTY: onselect
	private javax.el.ValueExpression onselect;

	public void setOnselect(javax.el.ValueExpression onselect) {
		this.onselect = onselect;
	}

	// PROPERTY: readonly
	private javax.el.ValueExpression readonly;

	public void setReadonly(javax.el.ValueExpression readonly) {
		this.readonly = readonly;
	}

	// PROPERTY: size
	private javax.el.ValueExpression size;

	public void setSize(javax.el.ValueExpression size) {
		this.size = size;
	}

	// PROPERTY: style
	private javax.el.ValueExpression style;

	public void setStyle(javax.el.ValueExpression style) {
		this.style = style;
	}

	// PROPERTY: styleClass
	private javax.el.ValueExpression styleClass;

	public void setStyleClass(javax.el.ValueExpression styleClass) {
		this.styleClass = styleClass;
	}

	// PROPERTY: tabindex
	private javax.el.ValueExpression tabindex;

	public void setTabindex(javax.el.ValueExpression tabindex) {
		this.tabindex = tabindex;
	}

	// PROPERTY: title
	private javax.el.ValueExpression title;

	public void setTitle(javax.el.ValueExpression title) {
		this.title = title;
	}

	// General Methods
	public String getRendererType() {
		return "HTMLLocaleRenderer";
	}

	public String getComponentType() {
		return "LocaleUIComponent";
	}

	protected void setProperties(UIComponent component) {
		super.setProperties(component);
		javax.faces.component.UIInput input = null;
		try {
			input = (javax.faces.component.UIInput) component;
		} catch (ClassCastException cce) {
			throw new IllegalStateException("Component " + component.toString()
					+ " not expected type.  Expected: javax.faces.component.UIInput.  Perhaps you're missing a tag?");
		}

		if (converter != null) {
			if (!converter.isLiteralText()) {
				input.setValueExpression("converter", converter);
			} else {
				Converter conv = FacesContext.getCurrentInstance().getApplication().createConverter(
						converter.getExpressionString());
				input.setConverter(conv);
			}
		}

		if (converterMessage != null) {
			input.setValueExpression("converterMessage", converterMessage);
		}

		if (immediate != null) {
			input.setValueExpression("immediate", immediate);
		}

		if (required != null) {
			input.setValueExpression("required", required);
		}

		if (requiredMessage != null) {
			input.setValueExpression("requiredMessage", requiredMessage);
		}

		if (validator != null) {
			input.addValidator(new MethodExpressionValidator(validator));
		}
		if (validatorMessage != null) {
			input.setValueExpression("validatorMessage", validatorMessage);
		}

		if (value != null) {
			input.setValueExpression("value", value);
		}

		if (valueChangeListener != null) {
			input.addValueChangeListener(new MethodExpressionValueChangeListener(valueChangeListener));
		}
		if (accesskey != null) {
			input.setValueExpression("accesskey", accesskey);
		}
		if (alt != null) {
			input.setValueExpression("alt", alt);
		}
		if (autocomplete != null) {
			input.setValueExpression("autocomplete", autocomplete);
		}
		if (dir != null) {
			input.setValueExpression("dir", dir);
		}
		if (disabled != null) {
			input.setValueExpression("disabled", disabled);
		}
		if (label != null) {
			input.setValueExpression("label", label);
		}
		if (lang != null) {
			input.setValueExpression("lang", lang);
		}
		if (maxlength != null) {
			input.setValueExpression("maxlength", maxlength);
		}
		if (onblur != null) {
			input.setValueExpression("onblur", onblur);
		}
		if (onchange != null) {
			input.setValueExpression("onchange", onchange);
		}
		if (onclick != null) {
			input.setValueExpression("onclick", onclick);
		}
		if (ondblclick != null) {
			input.setValueExpression("ondblclick", ondblclick);
		}
		if (onfocus != null) {
			input.setValueExpression("onfocus", onfocus);
		}
		if (onkeydown != null) {
			input.setValueExpression("onkeydown", onkeydown);
		}
		if (onkeypress != null) {
			input.setValueExpression("onkeypress", onkeypress);
		}
		if (onkeyup != null) {
			input.setValueExpression("onkeyup", onkeyup);
		}
		if (onmousedown != null) {
			input.setValueExpression("onmousedown", onmousedown);
		}
		if (onmousemove != null) {
			input.setValueExpression("onmousemove", onmousemove);
		}
		if (onmouseout != null) {
			input.setValueExpression("onmouseout", onmouseout);
		}
		if (onmouseover != null) {
			input.setValueExpression("onmouseover", onmouseover);
		}
		if (onmouseup != null) {
			input.setValueExpression("onmouseup", onmouseup);
		}
		if (onselect != null) {
			input.setValueExpression("onselect", onselect);
		}
		if (readonly != null) {
			input.setValueExpression("readonly", readonly);
		}
		if (size != null) {
			input.setValueExpression("size", size);
		}
		if (style != null) {
			input.setValueExpression("style", style);
		}
		if (styleClass != null) {
			input.setValueExpression("styleClass", styleClass);
		}
		if (tabindex != null) {
			input.setValueExpression("tabindex", tabindex);
		}
		if (title != null) {
			input.setValueExpression("title", title);
		}
	}

	// Methods From TagSupport
	public int doStartTag() throws JspException {
		try {
			return super.doStartTag();
		} catch (Exception e) {
			Throwable root = e;
			while (root.getCause() != null) {
				root = root.getCause();
			}
			throw new JspException(root);
		}
	}

	public int doEndTag() throws JspException {
		try {
			return super.doEndTag();
		} catch (Exception e) {
			Throwable root = e;
			while (root.getCause() != null) {
				root = root.getCause();
			}
			throw new JspException(root);
		}
	}

	// RELEASE
	public void release() {
		super.release();

		// component properties
		this.converter = null;
		this.converterMessage = null;
		this.immediate = null;
		this.required = null;
		this.requiredMessage = null;
		this.validator = null;
		this.validatorMessage = null;
		this.value = null;
		this.valueChangeListener = null;

		// rendered attributes
		this.accesskey = null;
		this.alt = null;
		this.autocomplete = null;
		this.dir = null;
		this.disabled = null;
		this.label = null;
		this.lang = null;
		this.maxlength = null;
		this.onblur = null;
		this.onchange = null;
		this.onclick = null;
		this.ondblclick = null;
		this.onfocus = null;
		this.onkeydown = null;
		this.onkeypress = null;
		this.onkeyup = null;
		this.onmousedown = null;
		this.onmousemove = null;
		this.onmouseout = null;
		this.onmouseover = null;
		this.onmouseup = null;
		this.onselect = null;
		this.readonly = null;
		this.size = null;
		this.style = null;
		this.styleClass = null;
		this.tabindex = null;
		this.title = null;
	}

	public String getDebugString() {
		return "id: " + this.getId() + " class: " + this.getClass().getName();
	}

}
